package com.ohuang.baseapp.utils;



import ohos.app.Context;
import ohos.net.NetCapabilities;
import ohos.net.NetHandle;
import ohos.net.NetManager;
import ohos.wifi.WifiDevice;


public class NetWorkUtils {
    /**
     * 判断网络是否可用
     *
     * @return
     */
    public static Boolean isHasNetwork(Context context) {
        NetManager manager = NetManager.getInstance(context);
        NetHandle netHandle = manager.getDefaultNet();
        NetCapabilities cap = manager.getNetCapabilities(netHandle);
        String str = "";
        if (cap.hasBearer(NetCapabilities.BEARER_WIFI)) {
            WifiDevice wifiDevice = WifiDevice.getInstance(context);
            str = "当前wifi:" + wifiDevice.getLinkedInfo().get().getSsid();
            return true;
        } else if (cap.hasBearer(NetCapabilities.BEARER_CELLULAR)) {
            str = "当前使用移动网络";
            return true;
        } else {//没网
            str = "当前没有网络";
            return false;
        }
    }

}
